package com.gh.ok.ui

import android.os.Bundle
import android.view.View
import com.gh.ok.R
import com.gh.ok.const.EventConst
import com.gh.ok.databinding.ActivityEventbusSampleBinding
import com.gh.ok.entity.UserInfo
import com.gyf.immersionbar.ktx.immersionBar
import com.ok.common.base.BaseActivity
import com.ok.common.base.BaseEvent
import com.ok.common.utils.EventUtils

/**
 * 框架封装的EventBus使用Sample
 */
class EventBusSampleActivity : BaseActivity<ActivityEventbusSampleBinding>() {

    override fun initImmersionBar() {
        immersionBar {
            titleBar(mBinding.viewTitle.titleBar)
            navigationBarColor(R.color.bgHomeTab)
        }
    }

    override fun initView(savedInstanceState: Bundle?) {
        mBinding.apply {
            viewTitle.tvTitle.text = intent.extras?.getString("title")
        }
    }

    override fun initListener() {
        super.initListener()
        mBinding.viewTitle.ibtnBack.setOnClickListener(this)
        mBinding.btnSendEvent.setOnClickListener(this)
        mBinding.btnSendEventExtraData.setOnClickListener(this)
    }

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v?.id) {
            R.id.ibtn_back -> {
                finish()
            }

            R.id.btn_send_event -> {
                EventUtils.sendEvent(BaseEvent(EventConst.LOGIN_SUCCESS))
                finish()
            }

            R.id.btn_send_event_extra_data -> {
                EventUtils.sendEvent(
                    BaseEvent(
                        EventConst.LOGIN_SUCCESS,
                        UserInfo(userAge = 30, userName = "小志", mobile = "15061009456")
                    )
                )
                finish()
            }
        }
    }

}